#include<stdio.h>
#include<stdlib.h>

typedef struct Node
{
	int data;
	struct Node *next;
}*List;
List create_list(List head){
	if(head == NULL){
		head=(List)malloc(sizeof(struct Node));
		head->next=NULL;
	}
	List p=head;
	int x;
	scanf("%d",&x);
	while(x!=-1){
		List node=(List)malloc(sizeof(struct Node));
		node->data=x;
		node->next=p->next;
		p->next=node;
		p=node;
		scanf("%d",&x);
	}
	p->next=NULL;
	return head;
}
void printL(List head){
	List p=head->next;
	while(p){
		printf("%d->",p->data);
		p=p->next;
	}
}
void deleteDuplicatedNum(List head){//带头结点
    List p=head->next;
    List pre;//遍历前驱指针
    while(p){
        List q=p->next;//从p后一元素开始遍历整个链表
        pre=p;
        while(q){
            if(p->data==q->data){
                pre->next=q->next;
                free(q);
                q=pre->next;//q指针指回链表
            }else{
                pre=q;//需要保存待删除结点的前一个结点
                q=q->next;//后移
            }
        }
        p=p->next;
    }
}

void del(List head){
	List p=head->next;
	List pre;
	while(p){
		List q=p->next;
		pre=q;
		while(q){
			if(p->data==q->data){
				pre->next=q->next;
				free(q);
				q=pre->next;//指回链表
			}else{
				pre=q;
				q=q->next;
			}
		}
		p=p->next;
	}
}
int main(){
    List head=NULL;
    head=create_list(head);
    
    deleteDuplicatedNum(head);
    printL(head);
    return 0;
}